//
//  SaTMNewPublicPhotoCollectionViewCell.m
//  saas
//
//  Created by apple on 2020/11/30.
//  Copyright © 2020 fangmao. All rights reserved.
//

#import "SaTMNewPublicPhotoCollectionViewCell.h"
#import "SaImageZoomView.h"
#import "SDWebImageManager.h"


@interface SaTMNewPublicPhotoCollectionViewCell ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) UIImage *displayImage;
@property (nonatomic, strong) SaImageZoomView *imgView;
@property (nonatomic, assign) BOOL toackBool;


@end



@implementation SaTMNewPublicPhotoCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.toackBool = NO;
        [self configUI];
        
        
    }
    return self;
}

- (void)configUI{
    [self.contentView addSubview:self.imgView];
    self.imgView.frame = self.contentView.bounds;

    
    
}

-(void)respondsTo_showOrHiddenNavigation{

//    self.toackBool = !self.toackBool;
//    
//    __weak typeof(self)weakSelf = self;
//    if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(hiddenOrShowNavigation:)]) {
//        [weakSelf.delegate hiddenOrShowNavigation:self.toackBool];
//    }
}


-(void)uploadPublicPhotoWithFiles:(id)files WaterText:(NSString *)waterText Type:(BOOL)type{
    if (type){
        
        
        NSString * str = [NSString stringWithFormat:@"%@",files[@"url"]];

            if ([str hasPrefix:@"http://"] || [str hasPrefix:@"https://"]) {
                [[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:files[@"url"]] options:nil progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
                    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
                        if (!image){
                            [self.imgView displayImage:IMAGE_NAME(@"zhanweitu")];
                        }else {
                            UIImage * img = [SaPublicWay addWatermarketWithOriginImage:image WaterText:waterText];
                            [self.imgView displayImage:img];
                            self.displayImage = img;
                        }
                    }];
            }
        
    }else{
        UIImage * img = [SaPublicWay addWatermarketWithOriginImage:files WaterText:waterText];
        [self.imgView displayImage:img];
//        self.displayImage = img;
    }
    
    
    
    
    
    
    
}
- (SaImageZoomView *)imgView{
    if (!_imgView) {
        _imgView = [SaImageZoomView new];
        _imgView.userInteractionEnabled = YES;
        UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsTo_showOrHiddenNavigation)];
        [_imgView addGestureRecognizer:ges];
        
    }
    return _imgView;
}

@end
